let userList: Array<User> = new Array(33).fill(0).map((_, idx) => ({
  id: idx + 1,
  name: `用户[${idx + 1}]`,
  age: Math.floor(Math.random() * 100),
  sex: Math.random() > 0.5 ? '男' : '女',
  email: '---'
}))

class MockService {

  /**
   * 分页查询用户数据
   * @param page 页码
   * @param pageSize 每页记录数
   * @returns 每页记录
   */
  queryPagedUserList(page: number, pageSize: number) {
    const start = pageSize * (page - 1)
    return Promise.resolve({
      total: userList.length,
      rows: userList.slice(start, start + pageSize)
    })
  }

  deleteUser(userId: number) {
    userList = userList.filter(user => user.id !== userId)
    return Promise.resolve({
      status: 0,
      message: '删除成功'
    })
  }
  
  editUser(user: User) {
    userList = userList.map(current => {
      return user.id === current.id ? user : current
    })
    return Promise.resolve({
      status: 0,
      message: '修改成功'
    })
  }
}

export const mockService = new MockService()